﻿var layer;
layui.use('layer', function () {
    layer = layui.layer;
});
function pop_edit_full(title, url) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
};
function pop_edit(title, url, w, h, isMax, isClose) {
    if (url == null || url == '') {
        return;
    }
    if (w == null || w == '') {
        w = 800;
    }
    if (h == null || h == '') {
        h = ($(window).height() - 50);
    };
    if (isMax == null || isMax == '') {
        isMax = false;
    };
    if (isClose == null || isClose == '') {
        isClose = 1;
    };
    layer.open({
        type: 2,
        area: [w + 'px', h + 'px'],
        fix: false, //不固定
        maxmin: isMax,
        shade: 0.4,
        title: title,
        content: url,
        closeBtn: isClose
    });
}
function pop_edit_Find(title, url, w, h, isMax, isClose) {
    if (url == null || url == '') {
        return;
    }
    if (w == null || w == '') {
        w = 800;
    }
    if (h == null || h == '') {
        h = ($(window).height() - 50);
    };
    if (isMax == null || isMax == '') {
        isMax = false;
    };
    if (isClose == null || isClose == '') {
        isClose = 1;
    };
    layer.open({
        type: 2,
        area: [w + 'px', h + 'px'],
        fix: false, //不固定
        maxmin: isMax,
        shade: 0.4,
        title: title,
        content: url,
        closeBtn: isClose,
        end: function () {
            $('#BtnFind').click();
        }
    });
}
function pop_edit_FindByBtn(title, url, w, h, isMax, isClose,finBtnName) {
    if (url == null || url == '') {
        return;
    }
    if (w == null || w == '') {
        w = 800;
    }
    if (h == null || h == '') {
        h = ($(window).height() - 50);
    };
    if (isMax == null || isMax == '') {
        isMax = false;
    };
    if (isClose == null || isClose == '') {
        isClose = 1;
    };
    layer.open({
        type: 2,
        area: [w + 'px', h + 'px'],
        fix: false, //不固定
        maxmin: isMax,
        shade: 0.4,
        title: title,
        content: url,
        closeBtn: isClose,
        end: function () {
            var btnObj = "#" + finBtnName;
            $(btnObj).click();
        }
    });
}
//必填项判断
function AutoCheckInfo() {
    //            alert($("span[innerHTML=*]").length);
    //只能用在文本框和下拉框的判定上面

    var isok = true;
    $("tt").parent().prev().find("input[type=text],select,textarea,input[type=radio],input[type=checkbox]").each(function (i) {
        var msg;
        if ($(this).is("input[type=radio]")) {
            if (!$("input[id^=" + $(this).attr("name") + "]:checked").val()) isok = false;
            var s = $.trim($(this).parent().prev().text()).replace(":", "").replace("：", "");
            if (!s) s = $.trim($(this).parent().parent().prev().text()).replace(":", "").replace("：", "");
            msg = "请选择 " + s + "！";
        }
        else if ($(this).is("input[type=checkbox]")) {
            if ($(":checkbox[id^=" + $(this).attr("name").replace("$0", "") + "]").attr("id")) {
                if ($("input:checkbox[id^=" + $(this).attr("name").replace("$0", "") + "]:checked").length == 0) isok = false;
                var s = $.trim($(this).parent().prev().text()).replace(":", "").replace("：", "");

                if (!s) s = $.trim($(this).parent().parent().prev().text()).replace(":", "").replace("：", "");
                msg = "请至少选择一个 " + s + "！";
            }
        }
        else if ($(this).is("input") || $(this).is("textarea")) {//如果是input控件
            if (!$.trim($(this).val())) isok = false;
            msg = "请填写 " + $.trim($(this).parent().prev().text()).replace(":", "").replace("：", "") + "！";
        }
        else {//如果是select控件
            if (!$.trim($(this).val()) && $.trim($(this).attr("id")) != "t_FDeptName_FCity"
               && $.trim($(this).attr("id")) != "t_FDeptName_FCountry"
                && $.trim($(this).attr("id")) != "PrjGovdeptid_FCountry") isok = false;
            msg = "请选择 " + $.trim($(this).parent().prev().text()).replace(":", "").replace("：", "") + "！";
        }
        if (!isok) {
            if ($(this).is("input") || $(this).is("textarea"))//应对日期控件未填时会赋值到按钮上。
                $(this).select();
            else
                $(this).focus();
            alert(msg);
            return false;
        }
    });

    if (!isok) {
        return false;
    }
    //其余的判定条件

    return true;
}